<?php

namespace commonsdk;

use OSS;

class Video_range {

    const KEY = 'xxx';
    const SECRET = 'xxx';
    const ENDPOINT = 'oss-cn-beijing.aliyuncs.com';
    const BUCKET = 'sss';

    static private $ossClient;

    //获取OSSclient
    static private function getOss() {
        if (!self::$ossClient) {
            self::$ossClient = new OSS\OssClient(self::KEY, self::SECRET, self::ENDPOINT);
        }
        return self::$ossClient;
    }

    //获取部分数据
    public function getPartData($getStoreFile, $start = 0, $offset = 5000000) {
        $end = $start + $offset - 1;
        $yu = $this->size - $start;
        //如果剩余数据长度小于分块大小则结束标记设空，否则OSS sdk报错
        if ($yu <= $offset) {
            $end = '';
        }
        $options = array(OSS\OssClient::OSS_RANGE => implode('-', [$start, $end]));
        $content = self::getOss()->getObject(self::BUCKET, $getStoreFile, $options);
        return $content;
    }

}
